import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    redirect: '/login'
  },

  {
    path: '/login',
    component: () => import('@/views/login.vue')
  },
  {
    path: '/home',
    component: () => import('@/views/home/index.vue'),
    children: [
      {
        path: '/',
        redirect: '/dashboard'
      },

      {
        // 首页
        path: '/dashboard',
        component: () => import('@/views/home/homepage'),
      },
      {
        //考勤
        path: '/attendances',
        component: () => import('@/views/home/check_workA'),
      },
      {
        //员工
        path: '/employees',
        component: () => import('@/views/home/employees'),
      },
      {
        //公司设置
        path: '/settings',
        component: () => import('@/views/home/companySET'),
      },
      {
        //审批
        path: '/approvals',
        component: () => import('@/views/home/exaANDapp'),
      },
      {
        //组织架构
        path: '/departments',
        component: () => import('@/views/home/organization'),
      },
      {
        //全选设置
        path: '/permissions',
        component: () => import('@/views/home/SelectAllSet'),
      },
      {
        //工资
        path: '/salarys',
        component: () => import('@/views/home/wages'),
      },
      {
        //老头好老头有社保
        path: '/social_securitys',
        component: () => import('@/views/home/socialSecurity'),
      },
    ]
  },
  {
    path: '*',
    component: () => import('@/components/404not.vue')
  }


]





const router = new VueRouter({
  routes
})



router.beforeEach((to, from, next) => {
  // 如果去的不是login 并且没有token就跳回登录页面
  if (to.path !== '/login' && !window.sessionStorage.getItem('ihrm')) {
    return next('/login')
  }
  next()
})

export default router
